import React from 'react'

export default class Post extends React.Component {
    delPost(element){
        console.log(element)
        fetch("http://localhost:8080/n",{
            method:'post',
            headers:{
                'Accept':'application/json,text/plain,*/*',/* 格式限制：json、文本、其他格式 */
                'Content-Type':'application/x-www-form-urlencoded'/* 请求内容类型 */
            },
            body:`id=${element.element.postId}`})
            window.location.reload()
    }
    constructor(){
        super()
        this.state={
          banners:[],
        }
      }
      componentDidMount(){
        fetch("http://localhost:8080/f")
        .then(res => res.json())
        .then(data => {
            this.setState({
                banners:data.data
            })
        })
    }
    render() {
        return (
            <div>
                {
                this.state.banners.map((element,index)=>{
                    return(
                        <ul style={{listStyleType:'none'}}>
                             <li key={index}>
                                <div>帖子id：{element.postId} 帖子内容：{element.postContent} 点赞数：{element.postLike} 收藏数：{element.postCollect} 评论数：{element.postTalk} 
                                &nbsp;&nbsp;&nbsp;<button onClick={()=>this.delPost({element})}>删除</button></div>
                            </li>
                        </ul>
                       
                    )
                })
                }
            </div>
        )
    }
}
    
